// 1. mysql/express/
const mysql = require("mysql");
const express = require("express");
const bodyParser = require('body-parser');

// 2. 引入路由模块
const Index=require("./routes/index")
const User=require("./routes/user")


// 3. 创建express对象
var server = express(); 


//4:下载 express-session 并且配置
const session = require("express-session");
server.use(session({
  secret:"128位随机字符", //安全字符串
  resave:false,          //每次请求是否都更新数据
  saveUninitialized:true, //初始化时保存数据
  cookie:{
    maxAge:1000 * 60 * 60 * 8
  }
}));


//app.js 录一段跨域配置
const cors = require("cors");
server.use(cors({
   origin:[
     "http://127.0.0.1:5500",
     "http://127.0.0.1:3000",
     "http://localhost:3000"
    ],
   credentials:true
}))


// 5. 绑定监听端口 3000
server.listen(3000);
//使用body-parser中间件
server.use(bodyParser.urlencoded({extended:false}));

// 6. 指定静态目录.保存图片资源
server.use(express.static("public"));

server.use("/index",Index);
server.use("/user",User);




